unit MemberFormUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids,DB, StdCtrls, DBCtrls, ExtCtrls;

type
  TMemberForm = class(TForm)
    DBGrid1: TDBGrid;
    Button1: TButton;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    DBImage1: TDBImage;
    OpenDialog1: TOpenDialog;
    DBNavigator1: TDBNavigator;
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure DBImage1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MemberForm: TMemberForm;

implementation

uses DataModuleUnit;

{$R *.dfm}
procedure TMemberForm.FormShow(Sender: TObject);
begin

  with DataModule1.ADOQuery1 do
  begin
    close;
    SQL.Clear;
    SQL.Add('select MemberCard.MemberCardID,MemberCard.StartTime,MemberCard.ExpirationTime,Car.CarPhoto,Car.CarID,Customer.CustomerID');
    SQL.Add(',Customer.CustomerName,Customer.IdentificationCard,Car.NumPlate,Car.Color,Car.CarPhoto');
    SQL.Add(' from  MemberCard,Car,Customer');
    SQL.Add(' where MemberCard.CarID=Car.CarID and Car.CustomerID=Customer.CustomerID');
//    SQL.Add('select * from MemberCard,Car where MemberCard.CarID=Car.CarID');
    Open;
    TNumericField(FieldByName('MemberCardID')).DisplayFormat:='00000000000';
    dbimage1.DataField:='CarPhoto';
//    DataModule1.ADOQuery1
  end;
  
end;

procedure TMemberForm.Button1Click(Sender: TObject);
var i:integer;
begin



  with DataModule1.ADOQuery1 do
  begin
    close;
    SQL.Clear;
    SQL.Add('select MemberCard.MemberCardID,MemberCard.StartTime,MemberCard.ExpirationTime');
    SQL.Add(',Customer.CustomerName,Customer.IdentificationCard,Car.NumPlate,Car.Color,Car.CarPhoto');
    SQL.Add(' from  MemberCard,Car,Customer');
    SQL.Add(' where MemberCard.CarID=Car.CarID and Car.CustomerID=Customer.CustomerID ');
    case ComboBox1.ItemIndex of
    0:
    begin
    SQL.Add('and MemberCard.MemberCardID like :CardID ');
    Parameters.ParamValues['CardID']:='%'+trim(ComboBox2.Text)+'%';
    end;
    1:
    begin
    SQL.Add('and Car.NumPlate like :NumPlate ');
    Parameters.ParamValues['NumPlate']:='%'+trim(ComboBox2.Text)+'%';
    end;
    end;
    Open;
    TNumericField(FieldByName('MemberCardID')).DisplayFormat:='00000000000';
  end;
end;

procedure TMemberForm.DBImage1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
  with DataModule1.ADOQuery1 do
  begin

    Edit;
    try
    TBlobField(FieldByName('CarPhoto')).LoadFromFile(OpenDialog1.FileName);
    Post;
    except
      Cancel;
    end;
  end;
  end;
end;

procedure TMemberForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
DataModule1.ADOQuery1.Close;
end;

end.
